import BaseService from './_BaseService'
import axios from 'axios'
import config from '../config'
import moment from 'moment'

class LocationHisService extends BaseService {
  root = '/ais/location-his-s'
  getHistoryData (southwest, northeast, fromTime, toTime) {
    let m1 = new moment(fromTime)
    let m2 = new moment(toTime)
    fromTime = m1.utc().format('YYYY-MM-DDTHH:mm:ss') + 'Z'
    toTime = m2.utc().format('YYYY-MM-DDTHH:mm:ss') + 'Z'
    // console.log('time is::::::::::::::', aisTime)
    let url = `${this.root}?size=99999`
    url += `&aisTime.greaterThan=${fromTime}`
    url += `&aisTime.lessThan=${toTime}`
    url += `&latitude.greaterThan=${southwest.lat}`
    url += `&latitude.lessThan=${northeast.lat}`
    url += `&longitude.greaterThan=${southwest.lng}`
    url += `&longitude.lessThan=${northeast.lng}`
    return axios.get(config.SERVER_URL + url, {responseType: 'json'})
      .then(resp => resp.data)
  }
}

export default new LocationHisService()
